package com.yunyan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunyan.entity.LoveData;
import com.yunyan.entity.SchoolData;
import com.yunyan.mapper.LoveMapper;
import com.yunyan.service.LoveService;
import com.yunyan.service.SchoolService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class LoveServiceImpl extends ServiceImpl<LoveMapper, LoveData> implements LoveService {


    @Resource
    private SchoolService schoolService;

    @Override
    public List<SchoolData> listLove(String userId) {
        List<LoveData> list = this.list(new LambdaQueryWrapper<LoveData>()
                .eq(LoveData::getUserId, userId)
        );

        if (list.isEmpty()) {
            return new ArrayList<>();
        }
        List<String> schoolIds = list.stream().map(LoveData::getSchoolId).collect(Collectors.toList());
        return schoolService.listByIds(schoolIds);
    }
}
